import numpy as np
import pandas as pd
import os
from dateutil.relativedelta import relativedelta
# import warnings
# warnings.filterwarnings('ignore')

def ratio_split(data, ratio):
    split_index = int(data.shape[0] * ratio)
    data_in = data[:split_index]
    data_out = data[split_index:]
    return data_in, data_out

class Train_eval_split():
    def __init__(self, feature, label, times, args) -> None:  
        self.args = args
        self.times = times
        self.feature = feature
        self.label = label      
            
    def cum_split(self):    
        feature_in = self.feature[:-self.args.label_range]
        feature_out = self.feature[-self.args.label_range:]
        label_in = self.label[:-self.args.label_range]
        label_out = self.label[-self.args.label_range:]
        times_in = self.times[:-self.args.label_range]
        times_out = self.times[-self.args.label_range:]
        feature_train, feature_eval = ratio_split(feature_in, self.args.train_ratio)
        label_train, label_eval = ratio_split(label_in, self.args.train_ratio)
        times_train, times_eval = ratio_split(times_in, self.args.train_ratio)
        print(f'当前样本内数据长度：{ len(times_in)},当前样本外数据长度：{ len(times_out)}')
        return feature_train, feature_eval, feature_out, label_train, label_eval, label_out, times_train, times_eval, times_out
    

    

